package com.peas.platform.module.icims;

import com.peas.platform.common.core.configuration.RequestContextUtil;
import com.peas.platform.common.core.constant.Constants;
import com.peas.platform.common.core.utils.RequestUtil;
import lombok.SneakyThrows;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

public class ThreadTestCase {

    @Test
    @SneakyThrows
    public void main() {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add("item" + i);
        }
        RequestUtil.initRequestId();
        String str = Thread.currentThread().getId() + ":" + Thread.currentThread().getName() + ":" + RequestContextUtil.getCurrentRequestId();
        System.out.println(str);
//        list.parallelStream().forEach(new Consumer<String>() {
//            @Override
//            public void accept(String s) {
//                String str = Thread.currentThread().getId() + ":" + Thread.currentThread().getName() + ":" + RequestContextUtil.getCurrentRequestId();
//                System.out.println(str);
//            }
//        });
        CountDownLatch countDownLatch = new CountDownLatch(list.size());
        for (String s : list) {
            new Thread(() -> {
                String str1 = Thread.currentThread().getId() + ":" + Thread.currentThread().getName() + ":" + RequestContextUtil.getCurrentRequestId();
                System.out.println(str1);
                countDownLatch.countDown();
            }).start();
        }
        countDownLatch.await();
    }
}
